from datetime import datetime
from enum import StrEnum
from extensions.ext_database import db
from models.common import OperationLog
class LogAction(StrEnum):
    DEL_ROBOT = "del_robot"
    CREATE_HW_VER = "create_hw_ver"
    DEL_HW_VER = "del_hw_ver"
    CREATE_FW_VER = "create_fw_ver"
    UPDATE_FW_VER = "update_fw_ver"
    DEL_FW_VER = "del_fw_ver"
    CREATE_ROBOT= "create_robot"
    CREATE_EMOJI= "create_emoji"
    UPDATE_EMOJI = "update_emoji"
    DEL_EMOJI = "del_emoji"
    CREATE_EMOJI_PACK= "create_emoji_pack"
    DEL_EMOJI_PACK = "del_emoji_pack"
    UPDATE_EMOJI_PACK = "update_emoji_pack"
    CREATE_CHARACTER = "create_character"
    UPDATE_CHARACTER = "update_character"
    DEL_CHARACTER = "del_character"
    CREATE_FUN_DOMAIN = "create_fun_domain"
    UPDATE_FUN_DOMAIN = "update_fun_domain"
    DEL_FUN_DOMAIN = "del_fun_domain"

    UPDATE_ROBOT_USER = "update_robot_user"
    DEL_ROBOT_USER = "del_robot_user"
    UPDATE_ROBOT_CONFIG = "update_robot_config"

    CREATE_FWVER_TASK = "create_fver_task"
    DELETE_FWVER_TASK = "delete_fver_task"
  


class LogService:
    @staticmethod
    def log(tenant_id, account_id, action, content, created_ip,submit:bool=True):
        """
        Log a message to the console.
        """
        try:
            log = OperationLog(
                tenant_id = tenant_id, # type:ignore
                account_id= account_id, # type:ignore
                action = action, # type:ignore
                content = content, # type:ignore
                created_at = datetime.now(), # type:ignore
                created_ip = created_ip, # type:ignore
            )
            db.session.add(log)
            if submit:
                db.session.commit()
        except Exception as e:
            print(e)